;----------------------------------------------------------------------------
;File name:	URAn_GEM.SH			Revision date:	1997.08.09
;Creator:	Ulf Ronald Andersson		Creation date:	1991.02.02
;(c)1992 by:	Ulf Ronald Andersson		All rights reserved
;Released as:	FREEWARE			(commercial sales forbidden)
;----------------------------------------------------------------------------
;Purpose:	Symbol & Macro library for GEM operations
;----------------------------------------------------------------------------
;Required header declarations:
;
;	include	"uran\STRUCT.SH"
;	include	"uran\URAn_SYS.SH"
;	include	"uran\URAn_GEM.SH"
;
;----------------------------------------------------------------------------
;	Library macros:
;
;gem_aes	func,arg,arg,arg...
;sub_aes	func
;sub_vdi	func[,handle]
;
;vq_aes		=> 0 if aes is missing
;vq_gdos	=> 0 if gdos is missing
;vq_vgdos	=> -2 if gdos is missing, otherwise => version code
;aes_redraw	redraws entire AES screen, including menu line
;
;NB:	Use "make GEM_links" to include all referred code modules.
;
;NB:	The VDI arrays 'contrl', 'intin', 'ptsin', 'intout', and 'ptsout'
;	are not created in this lib, but must be defined elsewhere.
;NB:	The arrays 'contrl', 'intin', 'intout' are also used for AES calls.
;
;NB:	The AES arrays 'global', 'addrin', 'addrout' are created in the lib.
;----------------------------------------------------------------------------
;	VDI FUNCTION DEFINITIONS
;
v_opnwk		equ	$000B7f01
v_clswk		equ	$00007f02
v_clrwk		equ	$00007f03
v_updwk		equ	$00007f04
;Op $05 has subop's given further below
v_pline		equ	$ff007f06
v_pmarker	equ	$ff007f07
v_gtext		equ	$01ff7f08
v_fillarea	equ	$ff007f09
v_cellarray	equ	$02ff7f0a
;Op $0b has subop's given further below
vst_height	equ	$01007f0c
vst_rotation	equ	$00017f0d
vs_color	equ	$00047f0e
vsl_type	equ	$00017f0f
vsl_width	equ	$01007f10
vsl_color	equ	$00017f11
vsm_type	equ	$00017f12
vsm_height	equ	$01007f13
vsm_color	equ	$00017f14
vst_font	equ	$00017f15
vst_color	equ	$00017f16
vsf_interior	equ	$00017f17
vsf_style	equ	$00017f18
vsf_color	equ	$00017f19
vq_color	equ	$00027f1a
;$1b
vrq_locator	equ	$01007f1c
vsm_locator	equ	vrq_locator
vrq_valuator	equ	$00017f1d
vsm_valuator	equ	vrq_valuator
vrq_choice	equ	$00017f1e
vsm_choice	equ	vrq_choice
vrq_string	equ	$01027f1f
vsm_string	equ	vrq_string
vswr_mode	equ	$00017f20
vsin_mode	equ	$00027f21
;$22
vql_attributes	equ	$00007f23
vqm_attributes	equ	$00007f24
vqf_attributes	equ	$00007f25
vqt_attributes	equ	$00007f26
vst_alignment	equ	$00027f27
v_opnvwk	equ	$000b7f64
v_clsvwk	equ	$00007f65
vq_extnd	equ	$00017f66
v_contour	equ	$01017f67
v_contourfill	equ	v_contour
vsf_perimeter	equ	$00017f68
v_get_pixel	equ	$01007f69
vst_effects	equ	$00017f6a
vst_point	equ	$00017f6b
vsl_ends	equ	$00027f6c
vro_cpyfm	equ	$04017f6d
vr_trnfm	equ	$00007f6e
vsc_form	equ	$00257f6f
vsf_udpat	equ	$00ff7f70
vsl_udsty	equ	$00017f71
vr_recfl	equ	$02007f72
vqin_mode	equ	$00017f73
vqt_extent	equ	$00ff7f74
vqt_width	equ	$00017f75
vex_timv	equ	$00007f76
vex_time	equ	vex_timv
vst_load_fonts	equ	$00017f77
vst_unload_fonts	equ	$00017f78
vrt_cpyfm	equ	$04037f79
v_show_c	equ	$00017f7a
v_hide_c	equ	$00007f7b
vq_mouse	equ	$00007f7c
vex_butv	equ	$00007f7d
vex_motv	equ	$00007f7e
vex_curv	equ	$00007f7f
vq_key_s	equ	$00007f80
vs_clip		equ	$02017f81
;;;vqt_name	equ	$xxxx7f82
;;;vqt_fontinfo	equ	$xxxx7f83
;
v_ftext		equ	$01ff7ff1	;\/ NVDI >=3.0, NB: ptsin size decides
v_ftext_offset	equ	$ffff7ff1	;/\ which function is used
;
;
;----------------------------------------------------------------------------
;	VDI subfunction definitions
;
vq_chcells	equ	$00000105
v_exit_cur	equ	$00000205
v_enter_cur	equ	$00000305
v_curup		equ	$00000405
v_curdown	equ	$00000505
v_curright	equ	$00000605
v_curleft	equ	$00000705
v_curhome	equ	$00000805
v_eeos		equ	$00000905	;\/ NB: info varies as to the
v_eeol		equ	$00000a05	;/\ order of these 2 functions
vs_curaddress	equ	$00020b05
v_curtext	equ	$00ff0c05
v_rvon		equ	$00000d05
v_rvoff		equ	$00000e05
vq_curaddress	equ	$00000f05
vq_tabstatus	equ	$00001005
v_hardcopy	equ	$00001105
v_dspcur	equ	$01001205
v_rmcur		equ	$00001305
v_form_adv	equ	$00001405
v_output_window	equ	$02001505
v_clear_disp_list=$00001605
;;;v_bit_image	equ	$xxxx1705
;
vs_palette	equ	$00013c05	;\
v_sound		equ	$00023d05	; > NB: PC-specific
vs_mute		equ	$00013e05	;/
;
vs_calibrate	equ	$00ff4c05
vq_calibrate	equ	$00004d05
;
vt_resolution	equ	$01005105
vt_axis		equ	$01005205
vt_origin	equ	$01005305
vq_tdimensions	equ	$00005405
vt_alignment	equ	$01005505
;
vqp_films	equ	$00005b05	;\
vqp_state	equ	$00005c05	; \
vsp_state	equ	$00155d05	;  \/ NB: info questionable
vsp_save	equ	$00005e05	;  /\
vsp_message	equ	$00009500	; /
vqp_error	equ	$00006005	;/
;
v_meta_extents	equ	$02006205
v_write_meta	equ	$ffff6305
vm_filename	equ	$00ff6405
;
v_offset	equ	$00016505
v_fontinit	equ	$00026605	;fonthead at (intin[0]<<16)|intin[1]
;
v_bar		equ	$0200010b
v_arc		equ	$0402020b
v_pieslice	equ	$0402030b
v_circle	equ	$0300040b
v_ellipse	equ	$0200050b
v_ellarc	equ	$0202060b
v_ellpie	equ	$0202070b
v_rbox		equ	$0200080b
v_rfbox		equ	$0200090b
v_justified	equ	$02ff0a0b
;
v_bez		equ	$ffff0d06	;NVDI >equ	2.10
v_bez_fill	equ	$ffff0d09	;NVDI >equ	2.10
;
;
;----------------------------------------------------------------------------
;	AES FUNCTION DEFINITIONS
;
appl_init	equ	$01000a
appl_read	equ	$21100b
appl_write	equ	$21100c
appl_find	equ	$01100d
appl_tplay	equ	$21100e
appl_trecord	equ	$11100f
appl_bvset	equ	$210010	;new
appl_yield	equ	$010011	;new
appl_search	equ	$131012	;new
appl_exit	equ	$010013
;
evnt_keybd	equ	$010014
evnt_button	equ	$350015
evnt_mouse	equ	$550016
evnt_mesag	equ	$011017
evnt_timer	equ	$210018
evnt_multi	equ	$1071019
evnt_dclick	equ	$21001a
;
menu_bar	equ	$11101e
menu_icheck	equ	$21101f
menu_ienable	equ	$211020
menu_tnormal	equ	$211021
menu_text	equ	$112022
menu_register	equ	$111023
menu_unregister	equ	$110024	;new
menu_click	equ	$210025	;new
;
objc_add	equ	$211028
objc_delete	equ	$111029
objc_draw	equ	$61102a
objc_find	equ	$41102b
objc_offset	equ	$13102c
objc_order	equ	$21102d
objc_edit	equ	$42102e
objc_change	equ	$81102f
objc_sysvar	equ	$430030	;3-D MTOS/MagiC
;
form_do		equ	$111032
form_xdo	equ	$222032
form_dial	equ	$910033
form_xdial	equ	$a10033
form_alert	equ	$111034
form_error	equ	$110035
form_center	equ	$051036
form_keybd	equ	$331037
form_button	equ	$221038
;
graf_rubberbox	equ	$430046
graf_rubbox	equ	$430046
graf_dragbox	equ	$830047
graf_movebox	equ	$610048
graf_mbox	equ	$610048
graf_growbox	equ	$810049
graf_shrinkbox	equ	$81004a
graf_watchbox	equ	$41104b
graf_slidebox	equ	$31104c
graf_handle	equ	$05004d
graf_mouse	equ	$11104e
graf_mkstate	equ	$05004f
;
scrp_read	equ	$011050
scrp_write	equ	$011051
scrp_clear	equ	$010052	;new
;
fsel_input	equ	$02205a
fsel_exinput	equ	$02305b	;new
;
wind_create	equ	$510064
wind_open	equ	$510065
wind_close	equ	$110066
wind_delete	equ	$110067
wind_get	equ	$250068
wind_set	equ	$610069
wind_find	equ	$21006a
wind_update	equ	$11006b
wind_calc	equ	$65006c
wind_new	equ	$00006d
;
rsrc_load	equ	$01106e
rsrc_free	equ	$01006f
rsrc_gaddr	equ	$210170
rsrc_saddr	equ	$211071
rsrc_obfix	equ	$111072
rsrc_rcfix	equ	$011073	;MTOS/MagiC
;
shel_read	equ	$012078
shel_write	equ	$312079
shel_get	equ	$11107a
shel_put	equ	$11107b
shel_find	equ	$01107c
shel_envrn	equ	$01207d
shel_rdef	equ	$01207e	;new
shel_wdef	equ	$00207f	;new
;
appl_getinfo	equ	$150082
;
xgrf_stepcalc	equ	$660082	;PC/MagiC  NB: opcode equ	appl_getinfo
xgrf_2box	equ	$910083	;PC/MagiC
;
form_popup	equ	$211087
form_xerr	equ	$211088	;MagiC >equ	2.0
;
;
;----------------------------------------------------------------------------
;	AES DATA DEFINITIONS
;
; Function flags for evnt_multi
;
MU_KEYBD	equ	$01
MU_BUTTON	equ	$02
MU_M1		equ	$04
MU_M2		equ	$08
MU_MESAG	equ	$10
MU_TIMER	equ	$20
;
;
; Function flag bits for evnt_multi
;
b_MU_KEYBD	equ	0
b_MU_BUTTON	equ	1
b_MU_M1		equ	2
b_MU_M2		equ	3
b_MU_MESAG	equ	4
b_MU_TIMER	equ	5
;
;----------------------------------------------------------------------------
;	Message event codes
;
MN_SELECTED	equ	$10
;
WM_REDRAW	equ	$14
WM_TOPPED	equ	$15
WM_CLOSED	equ	$16
WM_FULLED	equ	$17
WM_ARROWED	equ	$18
WM_HSLID	equ	$19
WM_VSLID	equ	$1A
WM_SIZED	equ	$1B
WM_MOVED	equ	$1C
WM_NEWTOP	equ	$1D	;in early MTOS only
WM_UNTOPPED	equ	$1E	;MTOS for info only
WM_ONTOP	equ	$1F	;MTOS for info only
WM_BOTTOM	equ	$21	;MTOS: call WIND_SET(WF_BOTTOM...)
WM_ICONIFY	equ	$22	;MTOS
WM_UNICONIFY	equ	$23	;MTOS
WM_ALLICONIFY	equ	$24	;MTOS
WM_TOOLBAR	equ	$25	;MTOS
;
AC_OPEN		equ	$28
AC_CLOSE	equ	$29
;
AP_TERM		equ	$32	;MTOS
AP_TFAIL	equ	$33	;MTOS
;
CT_KEY		equ	$35	;XCONTROL
;
AP_RESCHG	equ	$39	;MTOS
;
SHUT_COMPLETED	equ	$3C	;MTOS
RESCH_COMPLETED	equ	$3D	;MTOS
;
AP_DRAGDROP	equ	$3F	;MTOS
;
SH_WDRAW	equ	$48	;MTOS desktop redraw of windows for drive msg[3] (-1=all, 0=A:)
;
SC_CHANGED	equ	$50	;programs changing clipboard
;
CH_EXIT		equ	$5A	;MTOS msg[3]=childs ap_id,  msg[4]=exit_code
;
WM_M_BDROPPED	equ	$64	;
SM_M_SPECIAL	equ	$65	;MagiC screen manager commands
;
;----------------------------------------------------------------------------
;	Function codes for form_dial
;
FMD_START	equ	0
FMD_GROW	equ	1
FMD_SHRINK	equ	2
FMD_FINISH	equ	3
;
;----------------------------------------------------------------------------
;	Object type codes
;
G_BOX		equ	$14
G_TEXT		equ	$15
G_BOXTEXT	equ	$16
G_IMAGE		equ	$17
G_PROGDEF	equ	$18
G_IBOX		equ	$19
G_BUTTON	equ	$1A
G_BOXCHAR	equ	$1B
G_STRING	equ	$1C
G_FTEXT		equ	$1D
G_FBOXTEXT	equ	$1E
G_ICON		equ	$1F
G_TITLE		equ	$20
G_CICON		equ	$21
;
;------------------------------------
;	Object flags
;
NONE		equ	$00
SELECTABLE	equ	$01
DEFAULT		equ	$02
EXIT		equ	$04
EDITABLE	equ	$08
RBUTTON		equ	$10
LASTOB		equ	$20
TOUCHEXIT	equ	$40
HIDETREE	equ	$80
INDIRECT	equ	$100
FL3DMASK	equ	$600
FL3DNONE	equ	$000
FL3DIND		equ	$200
FL3DBAK		equ	$400
FL3DACT		equ	$600
;
;------------------------------------
;	Object states
;
NORMAL		equ	$00
SELECTED	equ	$01
CROSSED		equ	$02
CHECKED		equ	$04
DISABLED	equ	$08
OUTLINED	equ	$10
SHADOWED	equ	$20
;
;----------------------------------------------------------------------------
; 	Function codes for wind_set/wind_get
;
WF_KIND		equ	$01	;GET: p1 equ	window gadget flags
WF_NAME		equ	$02	;p1.p2 equ	*title
WF_INFO		equ	$03	;p1.p2 equ	*info
WF_WORKXYWH	equ	$04	;p1..p4 equ	x.y.w.h
WF_CURRXYWH	equ	$05	;p1..p4 equ	x.y.w.h
WF_PREVXYWH	equ	$06	;p1..p4 equ	x.y.w.h
WF_FULLXYWH	equ	$07	;p1..p4 equ	x.y.w.h
WF_HSLIDE	equ	$08	;p1 equ	horizontal slider pos 1..1000
WF_VSLIDE	equ	$09	;p1 equ	vertical slider pos 1..1000
WF_TOP		equ	$0A	;p1 equ	handle of topped window
WF_FIRSTXYWH	equ	$0B	;p1..p4 equ	x.y.w.h of first rectangle \/ p3=p4=0 means
WF_NEXTXYWH	equ	$0C	;p1..p4 equ	x.y.w.h of next rectangle  /\ end of list
WF_RESVD	equ	$0D
WF_NEWDESK	equ	$0E	;p1.p2 equ	*desktop object tree
WF_HSLSIZE	equ	$0F	;p1 equ	horizontal slider size 1..1000
WF_VSLSIZE	equ	$10	;p1 equ	vertical slider size 1..1000
WF_SCREEN	equ	$11	;p1.p2 equ	*buffer  p3.p4 equ	bytes  of aes menu/alert buffer
WF_COLOR	equ	$12
WF_DCOLOR	equ	$13
WF_OWNER	equ	$14	;MTOS GET: p1=ap_id p2=0(closed) p3=wind_above p4=wind_below
;	--------
WF_BEVENT	equ	$18	;MTOS: p1=1(untoppable)/0(normal)
WF_BOTTOM	equ	$19	;MTOS: p1 equ	handle of bottom window (excl desktop background)
WF_ICONIFY	equ	$1A	;MTOS GET: p1=0(normal)/non_0(iconified)  p2.p3=w.h of icon
WF_UNICONIFY	equ	$1B	;MTOS GET: p1..p4 equ	x.y.w.h from before iconification
;	--------
WF_TOOLBAR	equ	$1E	;MTOS: p1.p2 equ	*tree
WF_FTOOLBAR	equ	$1F	;MTOS GET:p1..p4 equ	x.y.w.h first rectangle \/ p3=p4=0
WF_NTOOLBAR	equ	$20	;MTOS GET:p1..p4 equ	x.y.w.h next rectangle  /\ at end
;
;
;
;----------------------------------------------------------------------------
;	Shape codes for graf_mouse
;
ARROW		equ	$00
TEXT_CRSR	equ	$01
HOURGLASS	equ	$02
BEE		equ	$02
POINT_HAND	equ	$03
FLAT_HAND	equ	$04
THIN_CROSS	equ	$05
THICK_CROSS	equ	$06
OUTLN_CROSS	equ	$07
USER_DEF	equ	$FF
M_OFF		equ	$100
M_ON		equ	$101
;
;
;----------------------------------------------------------------------------
;	Macro definitions & support variables
;
.MACRO	GEM_links
	_unidef	aes_redraw
	_unidef	sub_aes,sub_vdi,aes_data,vdi_data
.ENDM	GEM_links
;
;------------------------------------
;
huge_program	set	0
;
	_unidec	aes_redraw
	_unidec	sub_aes
	_unidec	aes_data
	_unidec	sub_vdi
	_unidec	vdi_data
;
;------------------------------------
;
	.macro	aes_redraw	
	_uniref	aes_redraw
	.ifeq	huge_program
	bsr	code_aes_redraw
	.else
	jsr	code_aes_redraw
	.endif
	.endm
;
	.macro	code_aes_redraw
;
	lea	zz_menu0(pc),a1
	lea	zz_menu1(pc),a2
	move	#14*24/4-1,d2
.movetree:
	move.l	(a1)+,(a2)+
	dbra	d2,.movetree
	lea	zz_menu1(pc),a2
	move	#14-1,d2
.obfix_loop:
	gem_aes	rsrc_obfix,d2,(a2)
	dbra	d2,.obfix_loop
;
	gem_aes	wind_get,#0,#5
	move	intout+2(pc),zz_wx
	move	intout+4(pc),zz_wy
	move	intout+6(pc),zz_ww
	move	intout+8(pc),zz_wh
	gem_aes	form_dial,#0,#0,#0,#0,#0,zz_wx,zz_wy,zz_ww,zz_wh
	tst	acc_flag
	bne.s	.done_menu_bar
	gem_aes	menu_bar,#1,zz_menu1
	gem_aes	menu_bar,#0,zz_menu1
.done_menu_bar:
	gem_aes	form_dial,#3,#0,#0,#0,#0,zz_wx,zz_wy,zz_ww,zz_wh
	rts
;
;NB:	There are 14 objects in each menu tree below
;
;'zz_menu0' is kept unaltered (no rsrc_obfix) to allow dynamic changes
;in font size and resolution between redraws
;
zz_menu0:
	dc.w	-1,1,4
	dc.w	25,0,0		*0*
	dc.l	0
	dc.w	0,0,80,25
;
	dc.w	4,2,2
	dc.w	20,0,0		*1*
	dc.l	$1100
	dc.w	0,0,80,$201
;
	dc.w	1,3,3
	dc.w	25,0,0		*2*
	dc.l	0
	dc.w	2,0,8,$301
;
	dc.w	2,-1,-1
	dc.w	32,0,0		*3*
	dc.l	zz_text1
	dc.w	0,0,8,$301
;
	dc.w	0,5,5
	dc.w	25,0,0		*4*
	dc.l	0
	dc.w	0,$301,80,23
;
	dc.w	4,6,13
	dc.w	20,0,0		*5*
	dc.l	$FF1100
	dc.w	2,0,17,8
;
	dc.w	7,-1,-1
	dc.w	28,0,0		*6*
	dc.l	zz_text2
	dc.w	0,0,17,1
;
	dc.w	8,-1,-1
	dc.w	28,0,8		*7*
	dc.l	zz_text3
	dc.w	0,1,17,1
;
	dc.w	9,-1,-1
	dc.w	28,0,0		*8*
	dc.l	zz_text4
	dc.w	0,2,17,1
;
	dc.w	10,-1,-1
	dc.w	28,0,0		*9*
	dc.l	zz_text5
	dc.w	0,3,17,1
;
	dc.w	11,-1,-1
	dc.w	28,0,0		*10*
	dc.l	zz_text6
	dc.w	0,4,17,1
;
	dc.w	12,-1,-1
	dc.w	28,0,0		*11*
	dc.l	zz_text7
	dc.w	0,5,17,1
;
	dc.w	13,-1,-1
	dc.w	28,0,0		*12*
	dc.l	zz_text8
	dc.w	0,6,17,1
;
	dc.w	5,-1,-1
	dc.w	28,32,0		*13*
	dc.l	zz_text9
	dc.w	0,7,17,1
zz_menu0_end:
;
zz_menu1:
	ds.b	zz_menu0_end-zz_menu0
;
;	Text data
;
zz_text1:	dc.b	' Redraw',0
zz_text2:	dc.b	'  Information... ',0
zz_text3:	dc.b	'-----------------',0
zz_text4:	dc.b	'  Accessory   1  ',0
zz_text5:	dc.b	'  Accessory   2  ',0
zz_text6:	dc.b	'  Accessory   3  ',0
zz_text7:	dc.b	'  Accessory   4  ',0
zz_text8:	dc.b	'  Accessory   5  ',0
zz_text9:	dc.b	'  Accessory   6  ',0
		dc.b	0,0
;
;	window data
;
zz_wx:	ds.w	1
zz_wy:	ds.w	1
zz_ww:	ds.w	1
zz_wh:	ds.w	1
;
	.endm	;aes_redraw
;
;------------------------------------
;
	.macro	vq_aes
	move	#$c9,d0
	trap	#2
	sub	#$c9,d0
	ext.l	d0
	.endm
;
;------------------------------------
;
	.macro	_appl_yield
	move.l	#$c9,d0
	trap	#2
	.endm
;
;------------------------------------
;
	.macro	vq_driver
	pea	(-1).w
	trap	#2
	.endm
;
;------------------------------------
;
	.macro	vq_gdos
	moveq	#-2,d0
	trap	#2
	addq	#2,d0
	ext.l	d0
	.endm
;
;------------------------------------
;
	.macro	vq_vgdos
	moveq	#-2,d0
	trap	#2
	.endm
;
;------------------------------------
;
	.macro	o_tree	tree
o_base_&tree:
o_df_&tree	set	-1
	.endm	;o_tree
;
	.macro	o_head	tree,name,next,child_1,child_x
&tree&name	equ	(*-o_base_&tree)/24
	.ifne	(*-o_base_&tree-24*&tree&name)
	.error	Object '&name' misaligned in tree '&tree'
	.endif
	.ifb	next
	dc.w	-1
	.else
	dc.w	&tree&next
	.endif
	.ifb	child_1
	dc.w	-1
	.else
	dc.w	&tree&child_1
	.endif
	.ifb	child_x
	dc.w	-1
	.else
	dc.w	&tree&child_x
	.endif
	.endm		;ends	.if o_head
;
	.macro	o_name	tree,name
&tree&name	equ	(*-o_base_&tree)/24
	.endm		;ends	.if o_name
;
;------------------------------------
;
	.macro	__inaes	op,v2,v3,v4,v5,v6,v7,v8,v9,va
__ind	set	(op) & _ind	;bit 30 flags indirection of addrin's
__aesii	set	((op)>>20) & 255	;sintin   equ	bits 27..20
__aesio	set	((op)>>16) & 15	;sintout  equ	bits 19..16
__aesai	set	((op)>>12) & 15	;saddrin  equ	bits 15..12
__aesao	set	((op)>>08) & 15	;saddrout equ	bits 11..8
__aesop	set	(op)&255	;opcode   equ	bits  7..0
__stoff	set	0
	.ifne	0<__aesii
	lea	intin,a0
	__stint	v2
	.ifeq	$19==__aesop
	.ifne	1<__aesii
	__stint	v3
	.ifeq	$69==__aesop
	.ifne	2<__aesii
	__stint	v4
	.ifne	3<__aesii
	__stint	v5
	.ifne	4<__aesii
	__stint	v6
	.ifne	5<__aesii
	__stint	v7
	.ifne	6<__aesii
	__stint	v8
	.ifne	7<__aesii
	__stint	v9
	.ifne	8<__aesii
	__stint	va
	.else
	gemaddrin	va
	.endif	;9ii
	.else
	gemaddrin	v9
	.endif	;8ii
	.else
	gemaddrin	v8
	.endif	;7ii
	.else
	gemaddrin	v7
	.endif	;6ii
	.else
	gemaddrin	v6
	.endif	;5ii
	.else
	gemaddrin	v5,v6
	.endif	;4ii
	.else
	gemaddrin	v4,v5
	.endif	;3ii
	.else
;special for wind_set(wind_id,func,..)		intin[2]... untouched
	.endif	;<>wind_set
	.else
	gemaddrin	v3,v4
	.endif	;2ii
	.else
;special for evnt_multi(flags,..,*msgbuf)	intin[1]... untouched
	gemaddrin	v3
	.endif	;<>evnt_multi
	.else
	gemaddrin	v2,v3,v4
	.endif	;1ii
	.endm	;__inaes
;
;------------------------------------
;
	.macro	__stint	data
	.ifb	data
__stoff	set	__stoff+2
	.exitm
	.endif
	.ifne	__stoff
	add	#__stoff,a0
__stoff	set	0
	.endif
	move	data,(a0)+
	.endm	;__stint
;
;------------------------------------
;
	.macro	__stlon	data
	.ifb	data
__stoff	set	__stoff+4
	.exitm
	.endif
	.ifne	__stoff
	add	#__stoff,a0
__stoff	set	0
	.endif
	move.l	data,(a0)+
	.endm	;__stlon
;
;------------------------------------
;
	.macro	__stptr	data,dest
	.ifb	data
	.exitm
	.endif
	pea	data
	move.l	(sp)+,dest
	.endm	;__stptr
;
;------------------------------------
;
	.macro	gemaddrin	v1,v2,v3
	.ifne	0<__aesai
	.ifne	__ind<>0
	lea	addrin,a0
	__stlon	v1
	.ifne	1<__aesai
	__stlon	v2
	.ifne	2<__aesai
	__stlon	v3
	.endif	;2<ai
	.endif	;1<ai
	.else	;__ind
	__stptr	v1,addrin
	.ifne	1<__aesai
	__stptr	v2,addrin+4
	.ifne	2<__aesai
	__stptr	v3,addrin+8
	.endif	;2<ai
	.endif	;1<ai
	.endif	;__ind
	.endif	;0<ai
	.endm	;gemaddrin
;
;
	.macro	gem_aes	op,v2,v3,v4,v5,v6,v7,v8,v9,va
	__inaes	op,v2,v3,v4,v5,v6,v7,v8,v9,va
	sub_aes	#op
	.endm	;gem_aes
;
;------------------------------------
;
	.macro	sub_aes	op
	_uniref	sub_aes
	move.l	op,d0
	.ifeq	huge_program
	bsr	code_sub_aes
	.else
	jsr	code_sub_aes
	.endif
	.endm	;sub_aes
;
	.macro	code_sub_aes
	_uniref	aes_data
	lea	contrl,a0
	clr.b	(a0)+		;opcode is < $100
	move.b	d0,(a0)+	;opcode equ	bits 7..0
	clr.b	d0
	lsl.l	#7,d0		;bits 31..25 are unused
	rol.l	#5,d0
	move	d0,(a0)+	;sintin   equ	bits 24..20
	clr	d0
	rol.l	#4,d0
	move	d0,(a0)+	;sintout  equ	bits 19..16
	clr	d0
	rol.l	#4,d0
	move	d0,(a0)+	;saddrin  equ	bits 15..12
	clr	d0
	rol.l	#4,d0
	move	d0,(a0)+	;saddrout equ	bits 11..8
	move.l	aesptr,d1
	move	#$c8,d0
	trap	#2
	move.l	intout,d0
	swap	d0		;d0 equ	intout[1]<<16+intout[0]
	move.l	addrout,d1	;d1 equ	addrout[0]
	rts
	.endm	;code_sub_aes
;
;------------------------------------
;
	.macro	sub_vdi	function,handle
	_uniref	sub_vdi
	move	handle,d1
	move.l	function,d0
	.ifeq	huge_program
	bsr	code_sub_vdi
	.else
	jsr	code_sub_vdi
	.endif
	.endm	;sub_vdi
;
	.macro	code_sub_vdi
	_uniref	vdi_data
	lea	contrl,a0
	clr.b	(a0)
	move.b	d0,1(a0)	;opcode equ	bits 7..0
	clr.b	d0
	rol.l	#8,d0
	cmp.b	#$ff,d0
	beq.s	.noptsin
	move	d0,2(a0)	;s_ptsin  equ	bits 31..24
.noptsin:
	clr	d0
	rol.l	#8,d0
	cmp.b	#$ff,d0
	beq.s	.nointin
	move	d0,6(a0)	;s_intin  equ	bits 23..16
.nointin:
	clr	d0
	rol.l	#8,d0
	bclr	#7,d0		;handle flagged by bit 15
	bne.s	.nohandle
	move	d1,12(a0)
.nohandle:
	cmp.b	#$7f,d0
	beq.s	.nosubop
	move	d0,10(a0)	;subop equ	bits 14..8
.nosubop:
	move.l	vdiptr,d1
	move	#$73,d0
	trap	#2
	move.l	intout,d0
	swap	d0		;d0 equ	intout[1]<<16+intout[0]
	move.l	ptsout,d1	;d1 equ	ptsout[0]
	rts
	.endm	;code_sub_vdi
;
;------------------------------------
;
	.macro	code_aes_data
aesptr:		dc.l	aes_pb
aes_pb:
aespb:		dc.l	contrl,global,intin,intout,addrin,addrout
global:
apversion:	dc.w	0
apcount:	dc.w	0
ap_id:		dc.w	0
apprivate:	dc.l	0
apptree:	dc.l	0
ap1resv:	dc.l	0
ap2resv:	dc.l	0
ap3resv:	dc.l	0
ap4resv:	dc.l	0
addrin:		dc.l	0,0,0
addrout:	dc.l	0
		.endm	;code_aes_data
;
;------------------------------------
;
	.macro	code_vdi_data
vdiptr:		dc.l	vdi_pb
vdi_pb:
vdipb:		dc.l	contrl,intin,ptsin,intout,ptsout
		.endm	;code_vdi_data
;
;----------------------------------------------------------------------------
;End of file:	URAn_GEM.SH
;----------------------------------------------------------------------------
